package BinaryTreePackage2;

/**
 * @author Lzm
 * @version 1.0
 */
public class isSymmetric_ {

  public boolean isSymmetric(TreeNode root) {
    if (root == null){
      return false;
    }
    return compare(root.left,root.right);
  }
  public boolean compare(TreeNode left,TreeNode right) {
    if (left != null && right == null){
      return false;
    }
    if (left == null && right != null){
      return false;
    }
    if (left != null && right != null && left.val != right.val){
      return false;
    }
    if (left != null && right != null && left.val == right.val){
      return true;
    }
    return compare(left.left,right.right) && compare(left.right,right.left);
  }
}
